import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'

export function getToken() {
  if(Cookies.get(TokenKey)){
    return Cookies.get(TokenKey)
  }

  if(getLocationToken()){
    return getLocationToken();
  }

  return null;
}

export function setToken(token) {
  Cookies.set(TokenKey, token)
}

export function setLocationToken(token) {
  localStorage.setItem(TokenKey,token);
}

function getLocationToken() {
  return localStorage.getItem(TokenKey);
}

export function removeToken() {
  Cookies.remove(TokenKey);
  localStorage.removeItem(TokenKey);
}
